package com.ionehe.group.common.uaa.ex.enums;

import com.ionehe.group.common.uaa.ex.exception.BusinessException;

import java.util.Objects;

/**
 * Copyright (c) 2020 ionehe.com
 * Date: 2020/10/10
 * Time: 下午3:08
 *
 * @author 2020年 <a href="mailto:a@ionehe.com">秀</a>
 */
public enum UserType {

    /**
     * 0：管理员
     */
    ADMIN(0, "管理员"),
    /**
     * 1：非管理员
     */
    NON_ADMIN(1, "非管理员");

    private Integer value;

    private String des;

    UserType(Integer value, String des){
        this.value = value;
        this.des = des;
    }

    public static UserType from(Integer value) {
        if (value == null) {
            return null;
        }
        for (UserType status : UserType.values()) {
            if (Objects.equals(value, status.getValue())) {
                return status;
            }
        }
        throw new BusinessException(ErrorMessages.ILLEGAL_OPERATION.toString());
    }

    public Integer getValue() {
        return value;
    }

    public String getDes() {
        return des;
    }
}
